package org.cqut.system.resource_course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.cqut.system.resource.domain.Resource;
import org.cqut.system.resource_course.domain.ResourceCourse;
import org.cqut.system.resource_course.service.ResourceCourseService;
import org.cqut.system.resource_course.mapper.ResourceCourseMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author XiAoXu
 */
@Service
public class ResourceCourseServiceImpl extends ServiceImpl<ResourceCourseMapper, ResourceCourse>
        implements ResourceCourseService {
    private final ResourceCourseMapper resourceCourseMapper;

    public ResourceCourseServiceImpl(ResourceCourseMapper resourceCourseMapper) {
        this.resourceCourseMapper = resourceCourseMapper;
    }

    @Override
    public List<Resource> selectResourceListByCourseId(String courseId) {
        return resourceCourseMapper.selectResourceList(courseId);
    }

    @Override
    public boolean removeResourceOutCourse(ResourceCourse resourceCourse) {
        QueryWrapper<ResourceCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id", resourceCourse.getCourseId());
        queryWrapper.eq("resource_id", resourceCourse.getResourceId());
        return remove(queryWrapper);
    }
}




